package com.retail.booking.controller;

import com.retail.booking.entity.request.BookingShareRecordRequest;
import com.retail.booking.entity.vo.BookingShareRecordVo;
import com.retail.booking.service.BookingShareRecordService;
import com.retail.core.common.AbstractCommonController;
import com.retail.core.entity.ParamReq;
import com.retail.core.entity.result.PageResult;
import com.retail.core.entity.result.Result;
import com.retail.global.annon.TraceLog;
import com.retail.global.security.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 海报分享记录 -每分享一次，生成一次记录 API
 *
 * @author Administrator
 */
@Api(tags = "海报分享记录 -每分享一次，生成一次记录 API")
@RestController
@RequestMapping("/bookingShareRecord")
public class BookingShareRecordController extends AbstractCommonController<BookingShareRecordService, BookingShareRecordRequest, BookingShareRecordVo> {

    private final BookingShareRecordService bookingShareRecordService;

    public BookingShareRecordController(BookingShareRecordService bookingShareRecordService) {
        this.bookingShareRecordService = bookingShareRecordService;
    }

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(bookingShareRecordService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存海报分享记录 -每分享一次，生成一次记录")
    public Result<Integer> save(@RequestBody BookingShareRecordRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(bookingShareRecordService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新海报分享记录 -每分享一次，生成一次记录")
    public Result<Integer> update(@RequestBody BookingShareRecordRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(bookingShareRecordService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("海报分享记录 -每分享一次，生成一次记录-查询")
    public Result<List<BookingShareRecordVo>> listPage(@RequestBody ParamReq req) {
        req.setManagerDept(LoginUserUtil.getPrincipal().getManagerDept());
        return super.listPage(bookingShareRecordService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("海报分享记录 -每分享一次，生成一次记录-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        req.setManagerDept(LoginUserUtil.getPrincipal().getManagerDept());
        return super.countPage(bookingShareRecordService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("海报分享记录 -每分享一次，生成一次记录-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<BookingShareRecordRequest> req) {
        req.setManagerDept(LoginUserUtil.getPrincipal().getManagerDept());
        return super.page(bookingShareRecordService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除海报分享记录 -每分享一次，生成一次记录")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(bookingShareRecordService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除海报分享记录 -每分享一次，生成一次记录")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(bookingShareRecordService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
